# SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR.e.V.)
# SPDX-FileContributor: Ferdinand Rewicki <ferdinand.rewicki@dlr.de>
#
# SPDX-License-Identifier: Apache-2.0
"""Preprocessing method to apply to the time series before clustering."""
import numpy as np
import pandas as pd


class DenoisedFeatures:
    """DenoisedFeatures."""

    def __init__(self, w: int):
        self.w = w

    def transform(self, X: list) -> list[np.ndarray]:
        """Denoise subsequences using a moving average.

        Parameters
        ----------
        X

        Returns
        -------
        Denoised Subsequences, np-list, shape = (n_cases)
        """
        result = []
        for x in X:
            result.append(
                pd.DataFrame(x.squeeze())
                .rolling(window=self.w, axis=0)
                .mean()
                .to_numpy()[self.w - 1 :]
                .flatten()
            )

        return result
